package com.rg.dao;

import com.rg.model.UserModel;
import com.rg.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;
//数据访问对象类，用于用户登录相关的数据库操作。
//selectUserByUserName方法根据用户名查询用户信息。
public class UserLogindao {
    public UserModel selectUserByUserName(String UserName){
        UserModel user = null;
        try{
            String sql="SELECT user_id userId,user_name userName,user_pwd userPwd,name Name,email email,phone phone,address address,roal roal FROM cake_user WHERE user_name=?";
            QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
            //query查询方法（上述sql语句，映射的对象，sql语句的条件）
            user=queryRunner.query(sql,new BeanHandler<UserModel>(UserModel.class),UserName);
        }catch (SQLException e){
            throw new RuntimeException(e);
        }
        return user;
    }
}

